package com.itheima.embedding;

import jakarta.annotation.PostConstruct;
import org.springframework.ai.document.Document;
import org.springframework.ai.reader.JsonReader;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RuleEmbedding {

    @Autowired
    private VectorStore vectorStore;

    @Value("classpath:rule.json")
    private Resource resource;

    @PostConstruct
    public void init(){
        JsonReader jsonReader = new JsonReader(resource, "type", "condition", "description");
        List<Document> documentList = jsonReader.get();
        vectorStore.add(documentList);
    }

}
